package cn.cqs.redisitem.Pojo;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class User implements Cloneable, Serializable {
    private Integer id;
    private String name;
    private Study study;
    private String sex;
//    使用transien修饰属性，对应数据将不被序列化
//    private transient String sex;

    public User() {
    }

    public User(Integer id, String name, String sex) {
        this.id = id;
        this.name = name;
        this.sex = sex;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
//  浅拷贝引用类型受影响，基本类型独立
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
//  深拷贝引用类型不受影响
    @Override
    public Object clone() throws CloneNotSupportedException {
        User newuser=(User) super.clone();
        newuser.setStudy((Study) this.study.clone());
        return newuser;
    }
//    protected使用在继承关系
    protected Object clone(String name)throws CloneNotSupportedException{
        System.out.println("---------protected---------");
        return null;
    }





//    @Override
//    public String toString() {
//        return "User{" +
//                "id=" + id +
//                ", name='" + name + '\'' +
//                ", sex='" + sex + '\'' +
//                '}';
//    }
}
